class Snake {
  // 表示蛇头的元素
  head: HTMLElement;
  // 获取蛇的容器
  element: HTMLElement;
  // 表示蛇身元素集合（包括蛇头）
  bodies: HTMLCollection;
  constructor() {
    this.head = document.querySelector('#snack > div') as HTMLElement;
    this.element = document.getElementById('snack') as HTMLElement;
    this.bodies = this.element.getElementsByTagName('div');
  }

  // 获取蛇的坐标（蛇头坐标）
  get X() {
    return this.head.offsetLeft;
  }

  get Y() {
    return this.head.offsetTop;
  }

  set X(value: number) {
    this.head.style.left = value + 'px';
  }

  set Y(value: number) {
    this.head.style.top = value + 'px';
  }

  // 蛇增加身体的方法
  addBody() {
    const body = document.createElement('div');
    this.element.appendChild(body);
  }
}

export default Snake;

